Skip to content

Tests: fix tests if running with self-built ffmpeg #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 14, 2025

Conversation

eromomon
Copy link
Contributor

@eromomon eromomon commented Aug 8, 2025

If self-building ffmpeg from the tag for development reasons, it's version is set as n6.1.2 (with n-prefix). This causes failures in the torchcodec tests. This patch handles such a case accounting for the n6.1.2 ffmpeg version format.

CC: @scotts, @NicolasHug, @dvrogozh

If self-building ffmpeg from the tag for development reasons, it's
version is set as `n6.1.2` (with n-prefix). This causes failures in
the torchcodec tests. This patch handles such a case accounting
for the `n6.1.2` ffmpeg version format.

Co-authored-by: Dmitry Rogozhkin <[email protected]>
Signed-off-by: Edgar Romo Montiel <[email protected]>
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 8, 2025
@dvrogozh
Copy link
Contributor

@eromomon, linter is likely giving the rightful issue:

test/test_metadata.py:12:1: F401 'torchcodec._core.get_ffmpeg_library_versions' imported but unused

Please, see https://github.com/pytorch/torchcodec/blob/main/CONTRIBUTING.md#code-formatting-and-type-checking on how to run linter locally.

I think MacOS issue might not be related to your change. Let's see linter issue fixed first.

@eromomon
Copy link
Contributor Author

Thank you for the observation, @dvrogozh. It has been fixed in the latest commit e003987.

@NicolasHug
Copy link
Member

Thanks for the PR @eromomon . I tried to push this directly but it seems I don't have permission to push on your branch. Could you please apply this patch, which adds a few comments? Then it should be good to merge. Thanks!

diff --git a/src/torchcodec/_core/custom_ops.cpp b/src/torchcodec/_core/custom_ops.cpp
index daec201..0e446a2 100644
--- a/src/torchcodec/_core/custom_ops.cpp
+++ b/src/torchcodec/_core/custom_ops.cpp
@@ -656,6 +656,10 @@ std::string get_stream_json_metadata(
 
 // Returns version information about the various FFMPEG libraries that are
 // loaded in the program's address space.
+// TODO: ideally we'd have a more robust way of getting the ffmpeg version,
+// we're using av_version_info() which is not standardized and shouldn't be
+// parsed by code (which we do!). See
+// https://github.com/pytorch/torchcodec/issues/100
 std::string _get_json_ffmpeg_library_versions() {
   std::stringstream ss;
   ss << "{\n";
diff --git a/test/utils.py b/test/utils.py
index 517100e..c258ac4 100644
--- a/test/utils.py
+++ b/test/utils.py
@@ -29,6 +29,9 @@ def cpu_and_cuda():
 
 def get_ffmpeg_major_version():
     ffmpeg_version = get_ffmpeg_library_versions()["ffmpeg_version"]
+    # When building FFmpeg from source there can be a `n` prefix in the version
+    # string.  This is quite brittle as we're using av_version_info(), which has
+    # no stable format. See https://github.com/pytorch/torchcodec/issues/100
     if ffmpeg_version.startswith("n"):
         ffmpeg_version = ffmpeg_version.removeprefix("n")
     return int(ffmpeg_version.split(".")[0])

and src/torchcodec/_core/custom_ops.cpp files

Co-authored-by: Nicolas Hug <[email protected]>
Signed-off-by: Edgar Romo Montiel <[email protected]>
@eromomon
Copy link
Contributor Author

Thank you for your feedback, @NicolasHug, I have updated the files to incorporate the mentioned comments.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eromomon !

@NicolasHug NicolasHug merged commit d84775a into pytorch:main Aug 14, 2025
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants